package com.xidian.zhiancloud.controller.exam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.exam.TExamPaper;
import com.xidian.zhiancloud.model.exam.TExamPlan;
import com.xidian.zhiancloud.model.exam.TrainPlan;
import com.xidian.zhiancloud.qo.BaseReqQuery;
import com.xidian.zhiancloud.service.exam.ITExamPlanService;

/**
 * 考试计划Controller
 * 
 * @author zhouweitao
 * @date 2021-03-08
 */
@RestController
@RequestMapping("/plan")
public class TExamPlanController   extends BaseController
{
    @Autowired
    private ITExamPlanService tExamPlanService;

    /**
     * 查询考试计划列表
     */
    @GetMapping("/list")
    public ResultDTO list( TExamPlan tExamPlan)
    {
        Page<TExamPlan> pagedata = tExamPlanService.selectTExamPlanList(tExamPlan);
        Map<String, Object> data = new HashMap<String, Object>();
		data.put("datalist", pagedata);
		data.put("PageNum", pagedata.getPageNum()+1);
		data.put("PageSize", pagedata.getPageSize());
		data.put("PageTotal", pagedata.getPages());
		data.put("total", pagedata.getTotal());
		return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }

  

    /**
     * 获取考试计划详细信息
     */
    @GetMapping(value = "/{id}")
    public ResultDTO getInfo(@PathVariable("id") Long id)
    {
    	
        return ResultDTO.successOf(tExamPlanService.selectTExamPlanById(id), GeneralResponseEnums.SUCCESS);
    }
    
    /**
     * 获取考试和计划的统计
     */
    @GetMapping(value = "/count/{id}")
    public ResultDTO getCount(@PathVariable("id") Long id)
    {
    	
        return ResultDTO.successOf(tExamPlanService.getCountPlanAndEaxm(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 新增考试计划
     */
    @PostMapping
    public ResultDTO add(@RequestBody TExamPlan tExamPlan)
    {
    	tExamPlanService.insertTExamPlan(tExamPlan);
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 修改考试计划
     */
    @PutMapping
    public ResultDTO edit(@RequestBody TExamPlan tExamPlan)
    {
    	tExamPlanService.updateTExamPlan(tExamPlan);
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除考试计划
     */
	@DeleteMapping("/{ids}")
    public ResultDTO remove(@PathVariable Long[] ids)
    {
		tExamPlanService.deleteTExamPlanByIds(ids);
		return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
	
	 /**
     * 查询个人考试计划
     */
    @GetMapping("/getExamByUser")
    public ResultDTO getPlanByUser( BaseReqQuery base,Long userId)
    {
    	Long id = 1L;
    	if(userId==null ) {
    		 id =getSessionUserid();
    	}else {
    		id =userId;
    	}
    	Page<TrainPlan> pagedata = tExamPlanService.getExamByUser(base,id);
        Map<String, Object> data = new HashMap<String, Object>();
		data.put("datalist", pagedata);
		data.put("PageNum", pagedata.getPageNum()+1);
		data.put("PageSize", pagedata.getPageSize());
		data.put("PageTotal", pagedata.getPages());
		data.put("total", pagedata.getTotal());
		return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
    }
	
}
